home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / doom / quake_ad.zip / HIPQW.ZIP / SRC / TRIGGERS.QC < prev    next >
Text File  |  1997-03-13  |  16KB  |  718 lines

  1.  
  2. entity stemp, otemp, s, old;
  3.  
  4.  
  5. void() trigger_reactivate =
  6. {
  7.     self.solid = SOLID_TRIGGER;
  8. };
  9.  
  10. //=============================================================================
  11.  
  12. float    SPAWNFLAG_NOMESSAGE = 1;
  13. float    SPAWNFLAG_NOTOUCH = 1;
  14.  
  15. // the wait time has passed, so set back up for another activation
  16. void() multi_wait =
  17. {
  18.     if (self.max_health)
  19.     {
  20.         self.health = self.max_health;
  21.         self.takedamage = DAMAGE_YES;
  22.         self.solid = SOLID_BBOX;
  23.     }
  24. };
  25.  
  26.  
  27. // the trigger was just touched/killed/used
  28. // self.enemy should be set to the activator so it can be held through a delay
  29. // so wait for the delay time before firing
  30. void() multi_trigger =
  31. {
  32.     if (self.nextthink > time)
  33.     {
  34.         return;        // allready been triggered
  35.     }
  36.  
  37.     if (self.classname == "trigger_secret")
  38.     {
  39.         if (self.enemy.classname != "player")
  40.             return;
  41.         found_secrets = found_secrets + 1;
  42.         WriteByte (MSG_ALL, SVC_FOUNDSECRET);
  43.     }
  44.  
  45.     if (self.noise)
  46.         sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  47.  
  48. // don't trigger again until reset
  49.     self.takedamage = DAMAGE_NO;
  50.  
  51.     activator = self.enemy;
  52.     
  53.     SUB_UseTargets();
  54.  
  55.     if (self.wait > 0)    
  56.     {
  57.         self.think = multi_wait;
  58.         self.nextthink = time + self.wait;
  59.     }
  60.     else
  61.     {    // we can't just remove (self) here, because this is a touch function
  62.         // called wheil C code is looping through area links...
  63.         self.touch = SUB_Null;
  64.         self.nextthink = time + 0.1;
  65.         self.think = SUB_Remove;
  66.     }
  67. //hip
  68. //MED 12/01/96 added cnt stuff
  69.    if (self.cnt > 0)
  70.       {
  71.       self.cnt = self.cnt - 1;
  72.       if (self.cnt == 0)
  73.          {
  74.          self.touch = SUB_Null;
  75.          self.nextthink = time + 0.1;
  76.          self.think = SUB_Remove;
  77.          }
  78.       }
  79. //hip
  80. };
  81.  
  82. void() multi_killed =
  83. {
  84.     self.enemy = damage_attacker;
  85.     multi_trigger();
  86. };
  87.  
  88. void() multi_use =
  89. {
  90.     self.enemy = activator;
  91.     multi_trigger();
  92. };
  93.  
  94. void() multi_touch =
  95. {
  96.     if (other.classname != "player")
  97.         return;
  98.     
  99. // if the trigger has an angles field, check player's facing direction
  100.     if (self.movedir != '0 0 0')
  101.     {
  102.         makevectors (other.angles);
  103.         if (v_forward * self.movedir < 0)
  104.             return;        // not facing the right way
  105.     }
  106.     
  107.     self.enemy = other;
  108.     multi_trigger ();
  109. };
  110.  
  111. /*QUAKED trigger_multiple (.5 .5 .5) ? notouch
  112. Variable sized repeatable trigger.  Must be targeted at one or more entities.  If "health" is set, the trigger must be killed to activate each time.
  113. If "delay" is set, the trigger waits some time after activating before firing.
  114. "wait" : Seconds between triggerings. (.2 default)
  115. //hip
  116. //MED 12/01/96 added count field
  117. "cnt" how many times it can be triggered (infinite default)
  118. //hip
  119. If notouch is set, the trigger is only fired by other entities, not by touching.
  120. NOTOUCH has been obsoleted by trigger_relay!
  121. sounds
  122. 1)    secret
  123. 2)    beep beep
  124. 3)    large switch
  125. 4)
  126. set "message" to text string
  127. */
  128. void() trigger_multiple =
  129. {
  130.     if (self.sounds == 1)
  131.     {
  132.         precache_sound ("misc/secret.wav");
  133.         self.noise = "misc/secret.wav";
  134.     }
  135.     else if (self.sounds == 2)
  136.     {
  137.         precache_sound ("misc/talk.wav");
  138.         self.noise = "misc/talk.wav";
  139.     }
  140.     else if (self.sounds == 3)
  141.     {
  142.         precache_sound ("misc/trigger1.wav");
  143.         self.noise = "misc/trigger1.wav";
  144.     }
  145.     
  146.     if (!self.wait)
  147.         self.wait = 0.2;
  148.     self.use = multi_use;
  149.  
  150.     InitTrigger ();
  151.  
  152.     if (self.health)
  153.     {
  154.         if (self.spawnflags & SPAWNFLAG_NOTOUCH)
  155.             objerror ("health and notouch don't make sense\n");
  156.         self.max_health = self.health;
  157.         self.th_die = multi_killed;
  158.         self.takedamage = DAMAGE_YES;
  159.         self.solid = SOLID_BBOX;
  160.         setorigin (self, self.origin);    // make sure it links into the world
  161.     }
  162.     else
  163.     {
  164.         if ( !(self.spawnflags & SPAWNFLAG_NOTOUCH) )
  165.         {
  166.             self.touch = multi_touch;
  167.         }
  168.     }
  169. //hip
  170. //MED 12/01/96 added cnt stuff
  171.    if (self.cnt == 0)
  172.       self.cnt = -1;
  173. //hip
  174. };
  175.  
  176.  
  177. /*QUAKED trigger_once (.5 .5 .5) ? notouch
  178. Variable sized trigger. Triggers once, then removes itself.  You must set the key "target" to the name of another object in the level that has a matching
  179. "targetname".  If "health" is set, the trigger must be killed to activate.
  180. If notouch is set, the trigger is only fired by other entities, not by touching.
  181. if "killtarget" is set, any objects that have a matching "target" will be removed when the trigger is fired.
  182. if "angle" is set, the trigger will only fire when someone is facing the direction of the angle.  Use "360" for an angle of 0.
  183. sounds
  184. 1)    secret
  185. 2)    beep beep
  186. 3)    large switch
  187. 4)
  188. set "message" to text string
  189. */
  190. void() trigger_once =
  191. {
  192.     self.wait = -1;
  193.     trigger_multiple();
  194. };
  195.  
  196. //=============================================================================
  197.  
  198. /*QUAKED trigger_relay (.5 .5 .5) (-8 -8 -8) (8 8 8)
  199. This fixed size trigger cannot be touched, it can only be fired by other events.  It can contain killtargets, targets, delays, and messages.
  200. */
  201. void() trigger_relay =
  202. {
  203.     self.use = SUB_UseTargets;
  204. };
  205.  
  206.  
  207. //=============================================================================
  208.  
  209. /*QUAKED trigger_secret (.5 .5 .5) ?
  210. secret counter trigger
  211. sounds
  212. 1)    secret
  213. 2)    beep beep
  214. 3)
  215. 4)
  216. set "message" to text string
  217. */
  218. void() trigger_secret =
  219. {
  220.     total_secrets = total_secrets + 1;
  221.     self.wait = -1;
  222.     if (!self.message)
  223.         self.message = "You found a secret area!";
  224.     if (!self.sounds)
  225.         self.sounds = 1;
  226.     
  227.     if (self.sounds == 1)
  228.     {
  229.         precache_sound ("misc/secret.wav");
  230.         self.noise = "misc/secret.wav";
  231.     }
  232.     else if (self.sounds == 2)
  233.     {
  234.         precache_sound ("misc/talk.wav");
  235.         self.noise = "misc/talk.wav";
  236.     }
  237.  
  238.     trigger_multiple ();
  239. };
  240.  
  241. //=============================================================================
  242.  
  243.  
  244. void() counter_use =
  245. {
  246.     local string junk;
  247.  
  248.     self.count = self.count - 1;
  249.     if (self.count < 0)
  250.         return;
  251.     
  252.     if (self.count != 0)
  253.     {
  254.         if (activator.classname == "player"
  255.         && (self.spawnflags & SPAWNFLAG_NOMESSAGE) == 0)
  256.         {
  257.             if (self.count >= 4)
  258.                 centerprint (activator, "There are more to go...");
  259.             else if (self.count == 3)
  260.                 centerprint (activator, "Only 3 more to go...");
  261.             else if (self.count == 2)
  262.                 centerprint (activator, "Only 2 more to go...");
  263.             else
  264.                 centerprint (activator, "Only 1 more to go...");
  265.         }
  266.         return;
  267.     }
  268.     
  269.     if (activator.classname == "player"
  270.     && (self.spawnflags & SPAWNFLAG_NOMESSAGE) == 0)
  271.         centerprint(activator, "Sequence completed!");
  272.     self.enemy = activator;
  273.     multi_trigger ();
  274. };
  275.  
  276. /*QUAKED trigger_counter (.5 .5 .5) ? nomessage
  277. Acts as an intermediary for an action that takes multiple inputs.
  278.  
  279. If nomessage is not set, t will print "1 more.. " etc when triggered and "sequence complete" when finished.
  280.  
  281. After the counter has been triggered "count" times (default 2), it will fire all of it's targets and remove itself.
  282. */
  283. void() trigger_counter =
  284. {
  285.     self.wait = -1;
  286.     if (!self.count)
  287.         self.count = 2;
  288.  
  289.     self.use = counter_use;
  290. };
  291.  
  292.  
  293. /*
  294. ==============================================================================
  295.  
  296. TELEPORT TRIGGERS
  297.  
  298. ==============================================================================
  299. */
  300.  
  301. float    PLAYER_ONLY    = 1;
  302. float    SILENT = 2;
  303.  
  304. void() play_teleport =
  305. {
  306.     local    float v;
  307.     local    string tmpstr;
  308.  
  309.     v = random() * 5;
  310.     if (v < 1)
  311.         tmpstr = "misc/r_tele1.wav";
  312.     else if (v < 2)
  313.         tmpstr = "misc/r_tele2.wav";
  314.     else if (v < 3)
  315.         tmpstr = "misc/r_tele3.wav";
  316.     else if (v < 4)
  317.         tmpstr = "misc/r_tele4.wav";
  318.     else
  319.         tmpstr = "misc/r_tele5.wav";
  320.  
  321.     sound (self, CHAN_VOICE, tmpstr, 1, ATTN_NORM);
  322.     remove (self);
  323. };
  324.  
  325. void(vector org) spawn_tfog =
  326. {
  327.     s = spawn ();
  328.     s.origin = org;
  329.     s.nextthink = time + 0.2;
  330.     s.think = play_teleport;
  331.  
  332.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  333.     WriteByte (MSG_BROADCAST, TE_TELEPORT);
  334.     WriteCoord (MSG_BROADCAST, org_x);
  335.     WriteCoord (MSG_BROADCAST, org_y);
  336.     WriteCoord (MSG_BROADCAST, org_z);
  337. };
  338.  
  339.  
  340. void() tdeath_touch =
  341. {
  342.     if (other == self.owner)
  343.         return;
  344.  
  345. // frag anyone who teleports in on top of an invincible player
  346.     if (other.classname == "player")
  347.     {
  348.         if (other.invincible_finished > time)
  349.             self.classname = "teledeath2";
  350.         if (self.owner.classname != "player")
  351.         {    // other monsters explode themselves
  352.             T_Damage (self.owner, self, self, 50000);
  353.             return;
  354.         }
  355.         
  356.     }
  357.  
  358.     if (other.health)
  359.     {
  360.         T_Damage (other, self, self, 50000);
  361.     }
  362. };
  363.  
  364.  
  365. void(vector org, entity death_owner) spawn_tdeath =
  366. {
  367. local entity    death;
  368.  
  369.     death = spawn();
  370.     death.classname = "teledeath";
  371.     death.movetype = MOVETYPE_NONE;
  372.     death.solid = SOLID_TRIGGER;
  373.     death.angles = '0 0 0';
  374.     setsize (death, death_owner.mins - '1 1 1', death_owner.maxs + '1 1 1');
  375.     setorigin (death, org);
  376.     death.touch = tdeath_touch;
  377.     death.nextthink = time + 0.2;
  378.     death.think = SUB_Remove;
  379.     death.owner = death_owner;
  380.     
  381.     force_retouch = 2;        // make sure even still objects get hit
  382. };
  383.  
  384. void() teleport_touch =
  385. {
  386. local entity    t;
  387. local vector    org;
  388.  
  389.     if (self.targetname)
  390.     {
  391.         if (self.nextthink < time)
  392.         {
  393.             return;        // not fired yet
  394.         }
  395.     }
  396.  
  397.     if (self.spawnflags & PLAYER_ONLY)
  398.     {
  399.         if (other.classname != "player")
  400.             return;
  401.     }
  402.  
  403. // only teleport living creatures
  404.     if (other.health <= 0 || other.solid != SOLID_SLIDEBOX)
  405.         return;
  406.  
  407.     SUB_UseTargets ();
  408.  
  409. // put a tfog where the player was
  410.     spawn_tfog (other.origin);
  411.  
  412.     t = find (world, targetname, self.target);
  413.     if (!t)
  414.         objerror ("couldn't find target");
  415.         
  416. // spawn a tfog flash in front of the destination
  417.     makevectors (t.mangle);
  418.     org = t.origin + 32 * v_forward;
  419.  
  420.     spawn_tfog (org);
  421.     spawn_tdeath(t.origin, other);
  422.  
  423. // move the player and lock him down for a little while
  424.     if (!other.health)
  425.     {
  426.         other.origin = t.origin;
  427.         other.velocity = (v_forward * other.velocity_x) + (v_forward * other.velocity_y);
  428.         return;
  429.     }
  430.  
  431.     setorigin (other, t.origin);
  432.     other.angles = t.mangle;
  433.     if (other.classname == "player")
  434.     {
  435.         other.fixangle = 1;        // turn this way immediately
  436.         other.teleport_time = time + 0.7;
  437.         if (other.flags & FL_ONGROUND)
  438.             other.flags = other.flags - FL_ONGROUND;
  439.         other.velocity = v_forward * 300;
  440.     }
  441.     other.flags = other.flags - other.flags & FL_ONGROUND;
  442. };
  443.  
  444. /*QUAKED info_teleport_destination (.5 .5 .5) (-8 -8 -8) (8 8 32)
  445. This is the destination marker for a teleporter.  It should have a "targetname" field with the same value as a teleporter's "target" field.
  446. */
  447. void() info_teleport_destination =
  448. {
  449. // this does nothing, just serves as a target spot
  450.     self.mangle = self.angles;
  451.     self.angles = '0 0 0';
  452.     self.model = "";
  453.     self.origin = self.origin + '0 0 27';
  454.     if (!self.targetname)
  455.         objerror ("no targetname");
  456. };
  457.  
  458. void() teleport_use =
  459. {
  460.     self.nextthink = time + 0.2;
  461.     force_retouch = 2;        // make sure even still objects get hit
  462.     self.think = SUB_Null;
  463. };
  464.  
  465. /*QUAKED trigger_teleport (.5 .5 .5) ? PLAYER_ONLY SILENT
  466. Any object touching this will be transported to the corresponding info_teleport_destination entity. You must set the "target" field, and create an object with a "targetname" field that matches.
  467.  
  468. If the trigger_teleport has a targetname, it will only teleport entities when it has been fired.
  469. */
  470. void() trigger_teleport =
  471. {
  472.     local vector o;
  473.  
  474.     InitTrigger ();
  475.     self.touch = teleport_touch;
  476.     // find the destination 
  477.     if (!self.target)
  478.         objerror ("no target");
  479.     self.use = teleport_use;
  480.  
  481.     if (!(self.spawnflags & SILENT))
  482.     {
  483.         precache_sound ("ambience/hum1.wav");
  484.         o = (self.mins + self.maxs)*0.5;
  485.         ambientsound (o, "ambience/hum1.wav",0.5 , ATTN_STATIC);
  486.     }
  487. };
  488.  
  489. /*
  490. ==============================================================================
  491.  
  492. trigger_setskill
  493.  
  494. ==============================================================================
  495. */
  496.  
  497. /*QUAKED trigger_setskill (.5 .5 .5) ?
  498. sets skill level to the value of "message".
  499. Only used on start map.
  500. */
  501. void() trigger_setskill =
  502. {
  503.     remove (self);
  504. };
  505.  
  506.  
  507. /*
  508. ==============================================================================
  509.  
  510. ONLY REGISTERED TRIGGERS
  511.  
  512. ==============================================================================
  513. */
  514.  
  515. void() trigger_onlyregistered_touch =
  516. {
  517.     if (other.classname != "player")
  518.         return;
  519.     if (self.attack_finished > time)
  520.         return;
  521.  
  522.     self.attack_finished = time + 2;
  523.     if (cvar("registered"))
  524.     {
  525.         self.message = "";
  526.         SUB_UseTargets ();
  527.         remove (self);
  528.     }
  529.     else
  530.     {
  531.         if (self.message != "")
  532.         {
  533.             centerprint (other, self.message);
  534.             sound (other, CHAN_BODY, "misc/talk.wav", 1, ATTN_NORM);
  535.         }
  536.     }
  537. };
  538.  
  539. /*QUAKED trigger_onlyregistered (.5 .5 .5) ?
  540. Only fires if playing the registered version, otherwise prints the message
  541. */
  542. void() trigger_onlyregistered =
  543. {
  544.     precache_sound ("misc/talk.wav");
  545.     InitTrigger ();
  546.     self.touch = trigger_onlyregistered_touch;
  547. };
  548.  
  549. //============================================================================
  550.  
  551. //hip
  552. //JIM
  553. void( entity ent, float amount ) hurt_setdamage =
  554.    {
  555.    ent.dmg = amount;
  556.    if ( !amount )
  557.       {
  558.       ent.solid = SOLID_NOT;
  559.       }
  560.    else
  561.       {
  562.       ent.solid = SOLID_TRIGGER;
  563.       }
  564.    ent.nextthink = -1;
  565.    };
  566. //hip
  567.  
  568. void() hurt_on =
  569. {
  570.     self.solid = SOLID_TRIGGER;
  571.     self.nextthink = -1;
  572. };
  573.  
  574. void() hurt_touch =
  575. {
  576.     if (other.takedamage)
  577.     {
  578.         self.solid = SOLID_NOT;
  579.         T_Damage (other, self, self, self.dmg);
  580.         self.think = hurt_on;
  581.         self.nextthink = time + 1;
  582.     }
  583.  
  584. //hip
  585. //MED 12/01/96 added count stuff
  586.       if (self.cnt > 0)
  587.          {
  588.          self.cnt = self.cnt - 1;
  589.          if (self.cnt == 0)
  590.             {
  591.             self.touch = SUB_Null;
  592.             self.nextthink = time + 0.1;
  593.             self.think = SUB_Remove;
  594.             }
  595.          }
  596.  
  597. //hip
  598.  
  599.     return;
  600. };
  601.  
  602. /*QUAKED trigger_hurt (.5 .5 .5) ?
  603. //hip
  604. //MED 12/01/96 added count field
  605. Any object touching this will be hurt
  606. set dmg to damage amount
  607. defalt dmg = 5
  608. "cnt" default infinite, how many times to trigger
  609. */
  610. void() trigger_hurt =
  611. {
  612.     InitTrigger ();
  613.     self.touch = hurt_touch;
  614.     if (!self.dmg)
  615.         self.dmg = 5;
  616. //hip
  617. //MED 12/01/96 added count stuff
  618.    if (self.cnt == 0)
  619.       self.cnt = -1;
  620. //hip
  621. };
  622.  
  623. //============================================================================
  624.  
  625. float PUSH_ONCE = 1;
  626.  
  627. void() trigger_push_touch =
  628. {
  629.     if (other.classname == "grenade")
  630.         other.velocity = self.speed * self.movedir * 10;
  631.     else if (other.health > 0)
  632.     {
  633.         other.velocity = self.speed * self.movedir * 10;
  634.         if (other.classname == "player")
  635.         {
  636.             if (other.fly_sound < time)
  637.             {
  638.                 other.fly_sound = time + 1.5;
  639.                 sound (other, CHAN_AUTO, "ambience/windfly.wav", 1, ATTN_NORM);
  640.             }
  641.         }
  642.     }
  643.     if (self.spawnflags & PUSH_ONCE)
  644.         remove(self);
  645. };
  646.  
  647.  
  648. /*QUAKED trigger_push (.5 .5 .5) ? PUSH_ONCE
  649. Pushes the player
  650. */
  651. void() trigger_push =
  652. {
  653.     InitTrigger ();
  654.     precache_sound ("ambience/windfly.wav");
  655.     self.touch = trigger_push_touch;
  656.     if (!self.speed)
  657.         self.speed = 1000;
  658. };
  659.  
  660. //============================================================================
  661.  
  662. void() trigger_monsterjump_touch =
  663. {
  664.     if ( other.flags & (FL_MONSTER | FL_FLY | FL_SWIM) != FL_MONSTER )
  665.         return;
  666.  
  667. // set XY even if not on ground, so the jump will clear lips
  668.     other.velocity_x = self.movedir_x * self.speed;
  669.     other.velocity_y = self.movedir_y * self.speed;
  670.     
  671.     if ( !(other.flags & FL_ONGROUND) )
  672.         return;
  673.     
  674.     other.flags = other.flags - FL_ONGROUND;
  675.  
  676.     other.velocity_z = self.height;
  677. //hip
  678.   //MED 12/01/96 added count stuff
  679.    if (self.cnt>0)
  680.       {
  681.       self.cnt = self.cnt - 1;
  682.       if (self.cnt == 0)
  683.          {
  684.          self.touch = SUB_Null;
  685.          self.nextthink = time + 0.1;
  686.          self.think = SUB_Remove;
  687.          }
  688.       }
  689. //hip
  690. };
  691.  
  692. /*QUAKED trigger_monsterjump (.5 .5 .5) ?
  693. Walking monsters that touch this will jump in the direction of the trigger's angle
  694. "speed" default to 200, the speed thrown forward
  695. "height" default to 200, the speed thrown upwards
  696. //hip
  697. //MED 12/01/96 added count field
  698. "cnt" default infinite, how many times to trigger
  699. //hip
  700. */
  701. void() trigger_monsterjump =
  702. {
  703.     if (!self.speed)
  704.         self.speed = 200;
  705.     if (!self.height)
  706.         self.height = 200;
  707.     if (self.angles == '0 0 0')
  708.         self.angles = '0 360 0';
  709. //hip
  710. //MED 12/01/96 added count stuff
  711.    if (self.cnt == 0)
  712.       self.cnt = -1;
  713. //hip
  714.     InitTrigger ();
  715.     self.touch = trigger_monsterjump_touch;
  716. };
  717.  
  718.